package Netflix;

import java.io.*;
import java.util.StringTokenizer;

/**
 * User: mtk
 * Date: 15/08/2007
 */
public class NF2MS {
    private final static String DELIM = ",:";

    private static void readMovie(String filename){
        try {
            FileReader fr = new FileReader(filename);
            BufferedReader is = new BufferedReader(fr);
            String s1 = is.readLine();
            while(s1 != null){
                StringTokenizer fileST=new StringTokenizer(s1,DELIM);

                int id = Integer.parseInt(fileST.nextToken());
                String year = fileST.nextToken();
                String title = fileST.nextToken();

                // do something with the Movie Data
                System.out.println("ID: " + id + " Year: " + year + " Title: " + title);

                s1 = is.readLine();
            }

        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void readRec(String filename){
        try {
            FileReader fr = new FileReader(filename);
            BufferedReader is = new BufferedReader(fr);
            String s1 = is.readLine();
            String movie = s1;

            System.out.println("Movie: "+ movie);

            s1 = is.readLine();
            while(s1 != null){
                StringTokenizer fileST=new StringTokenizer(s1,DELIM);
                
                int userID = Integer.parseInt(fileST.nextToken());
                int rank = Integer.parseInt(fileST.nextToken());
                String date = fileST.nextToken();

                // do something with the Recommendation
                //System.out.println("User: " + userID + " Rank: " + rank+ " Date: " + date);

                s1 = is.readLine();
            }

        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void readAllRec(){
        String MAIN_DIR = "Netflix";

        File dir = new File(MAIN_DIR);
        String[] children = dir.list();
        for (String filename : children) {
            readRec(MAIN_DIR + "\\" + filename);
        }
    }
    public static void main(String [] args){
        readMovie("Movies.txt");
        readAllRec();
    }
}
